<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('分数 列表')" />
    <style>
        td{
            max-width: 200px;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
        }
    </style>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>小项：</p>
                                <select onchange="$.table.search()" name="itemId" id="select2_item" class="form-control">
                                    <option th:each="item : ${itemList}" th:text="${item.name}" th:value="${item.id}"></option>
                                </select>
                            </li>
                            <li>
                                <p>选手：</p>
                                <input type="text" autocomplete="off" name="playerName"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="exportScore()" shiro:hasPermission="rec:register:view">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>

    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "js/score";

        $(function() {
            var options = {
                url: prefix + "/list",
                modalName: "成绩",
                pagination: false,
                columns: [
                    {
                        checkbox: true
                    },
                    {
                        field : 'registerId',
                        title : '报名ID',
                        visible: false
                    },
                    {
                        field : 'itemName',
                        title : '项目'
                    },
                    {
                        field : 'placeName',
                        title : '场地'
                    },
                    {
                        field : 'session',
                        title : '轮次'
                    },
                    {
                        field : 'odr',
                        title : '序号'
                    },
                    {
                        field : 'playerName',
                        title : '选手'
                    },
                    {
                        field : 'playerIdcard',
                        title : '身份证',
                        visible : false
                    },
                    {
                        field : 'valueScore',
                        title : '打分成绩',
                        formatter: function (value, row, index) {
                            return value ? value.toFixed(2) : "-";
                        },
                        visible : false
                    },
                    {
                        field : 'remarkScore',
                        title : '备注成绩',
                        formatter: function (value, row, index) {
                            return value ? value.toFixed(2) : "-";
                        },
                        visible : false
                    },
                    {
                        field : 'finalScore',
                        title : '最终成绩',
                        formatter: function (value, row, index) {
                            return value ? value.toFixed(2) : "-";
                        }
                    },
                    {
                        field : 'ranking',
                        title : '名次'
                    }
                ]
            };
            $.table.init(options);
        });

        // 导出成绩表
        function exportScore() {
            $.modal.loading("正在处理中，请稍后...");
            var siteId = $("#select2_site").val();
            var itemId = $("#select2_item").val();
            $.post(prefix + "/exportScore", {siteId, itemId} ,function(result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else {
                    $.modal.alertWarning(result.msg);
                }
                $.modal.closeLoading();
            });
        }

    </script>
</body>
</html>